/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package py.sysbi.entidades;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author PROYECTO_2
 */
@Entity
@Table(name = "receta_detalle")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "RecetaDetalle.findAll", query = "SELECT r FROM RecetaDetalle r"),
    @NamedQuery(name = "RecetaDetalle.findByReceta", query = "SELECT r FROM RecetaDetalle r WHERE r.recetaDetallePK.receta = :receta"),
    @NamedQuery(name = "RecetaDetalle.findById", query = "SELECT r FROM RecetaDetalle r WHERE r.recetaDetallePK.id = :id"),
    @NamedQuery(name = "RecetaDetalle.findByCantidad", query = "SELECT r FROM RecetaDetalle r WHERE r.cantidad = :cantidad"),
    @NamedQuery(name = "RecetaDetalle.findByDosis", query = "SELECT r FROM RecetaDetalle r WHERE r.dosis = :dosis")})
public class RecetaDetalle implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected RecetaDetallePK recetaDetallePK;
    @Column(name = "cantidad")
    private Integer cantidad;
    @Size(max = 255)
    @Column(name = "dosis")
    private String dosis;
    @JoinColumn(name = "receta", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Receta receta1;
    @JoinColumn(name = "medicamento", referencedColumnName = "id")
    @ManyToOne(fetch = FetchType.LAZY)
    private Medicamento medicamento;

    public RecetaDetalle() {
    }

    public RecetaDetalle(RecetaDetallePK recetaDetallePK) {
        this.recetaDetallePK = recetaDetallePK;
    }

    public RecetaDetalle(int receta, int id) {
        this.recetaDetallePK = new RecetaDetallePK(receta, id);
    }

    public RecetaDetallePK getRecetaDetallePK() {
        return recetaDetallePK;
    }

    public void setRecetaDetallePK(RecetaDetallePK recetaDetallePK) {
        this.recetaDetallePK = recetaDetallePK;
    }

    public Integer getCantidad() {
        return cantidad;
    }

    public void setCantidad(Integer cantidad) {
        this.cantidad = cantidad;
    }

    public String getDosis() {
        return dosis;
    }

    public void setDosis(String dosis) {
        this.dosis = dosis;
    }

    public Receta getReceta1() {
        return receta1;
    }

    public void setReceta1(Receta receta1) {
        this.receta1 = receta1;
    }

    public Medicamento getMedicamento() {
        return medicamento;
    }

    public void setMedicamento(Medicamento medicamento) {
        this.medicamento = medicamento;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (recetaDetallePK != null ? recetaDetallePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof RecetaDetalle)) {
            return false;
        }
        RecetaDetalle other = (RecetaDetalle) object;
        if ((this.recetaDetallePK == null && other.recetaDetallePK != null) || (this.recetaDetallePK != null && !this.recetaDetallePK.equals(other.recetaDetallePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "py.sysbi.entidades.RecetaDetalle[ recetaDetallePK=" + recetaDetallePK + " ]";
    }
    
}
